class CreateCustomers < ActiveRecord::Migration
  def self.up
    create_table :customers do |t|
      t.string :name                 ,:default=>'',:limit => 30,:null => false
      t.string :login_id             ,:limit => 15
      t.string :login_ip             ,:limit => 40
      t.string :password             ,:limit => 15 #对于WEB登录的用户直接在此表中验证登录。
      t.string :customer_from_type   ,:default=>'' #注明此用户来自己于何处,是WEB注册,还是作为常旅客添加的.
      t.string :sex                  ,:default=>'',:limit => 6
      t.string :age                  ,:default=>'',:limit => 6
      t.string :py                   ,:default=>'',:limit => 6
      t.date :birthday 
      t.string :phone                ,:default=>'',:limit => 25
      t.string :email                ,:default=>'',:limit => 25
      t.string :address              ,:default=>'',:limit => 50
      t.string :nationality          ,:default=>'',:limit => 20 #国籍
      t.integer :customer_type_id    ,:default=>1 ,:limit => 1 #such as customer,passenger,linkman 
      t.string :customer_level       ,:default=>'',:limit => 10 # such as vip etc...
      t.integer :customer_level_id   ,:default=>1 ,:limit => 0
      t.integer :card_type_id        ,:default=>1 ,:limit => 1  #证件类型
      t.string :card                 ,:default=>'',:limit => 50 #证件号码
      t.integer :phone_type_id       ,:limit => 1#电话类型 暂时不用
      t.integer :user_id             ,:default=>1 ,:limit => 2#信息录入人
      t.string :linkman              ,:default=>'',:limit => 10 #联系人
      t.string :linkman_phone        ,:default=>'',:limit => 25 #联系人电话
      t.string :remark               ,:default=>'' #备注
      t.string :customer_no          ,:default=>'',:limit => 30 #会员卡号
      t.integer :point               ,:default=>0 , :limit => 2  #当前积分
      t.integer :point_his           ,:default=>0 , :limit => 2 #历史积分
      t.integer :point_old           ,:default=>0 , :limit => 2 #当前积分 对应小绿人clients表中的integral字段数据
      t.integer :point_his_old       ,:default=>0 , :limit => 2 #历史积分 对应小绿人clients表中的integral_his字段数据
      t.integer :expenditure         ,:default=>0 , :limit => 2 #累计消费 实际钱数 （用户实际支付的款额）
      t.integer :expenditure_his     ,:default=>0 , :limit => 2 #历史消费金额 (跟客户相关的消费的总金额 包括积分兑换 税费 附加费 保险等）
      t.integer :expenditure_old     ,:default=>0 , :limit => 2 #累计金额 对应小绿人clients表中的expenditure字段数据
      t.integer :expenditure_his_old ,:default=>0 , :limit => 2 #历史消费金额 对应小绿人clients表中的expenditure_his字段数据
      t.integer :price               ,:default=>0 , :limit => 2 #票款合计 票面价总和
      t.integer :price_old           ,:default=>0 , :limit => 2 #票款合计 对应小绿人clients表中的priceNum字段数据
      t.integer :tax                 ,:default=>0 , :limit => 2 #税款合计
      t.integer :tax_old             ,:default=>0 , :limit => 2 #历史税款合计 对应小绿人clients表中的taxNum字段数据
      t.integer :fuel                ,:default=>0 , :limit => 2 #附加合计
      t.integer :fuel_old            ,:default=>0 , :limit => 2 #历史附加合计 对应小绿人clients表中的taxNum字段数据
      
      t.integer :is_locked           ,:limit => 1 ,:default => 0 #是否管理会要锁定 1为True 0为False
      t.integer :lock_version        , :default => 0 #乐观锁
      t.timestamps
    end
    
    #add_index :customers ,:phone ,:unique=>true
    
    Customer.create(:name => '未指定人员',:sex => '男',:customer_no=>'',:phone=>'',:card_type_id=>1,:card=>'',:birthday=>'2001-01-01',:address=>'',:customer_level => '',:customer_type_id =>1,:is_locked=>1)
    Customer.create(:name => 'John',:sex => '男',:customer_no=>'00000001',:phone=>'13800000000',:card_type_id=>1,:card=>'370000000000011111',:birthday=>'2001-01-01',:address=>'青岛',:customer_level => 'vip',:customer_type_id =>2)
    Customer.create(:name => 'Polo',:sex => '男',:customer_no=>'00000002',:phone=>'13800000001',:card_type_id=>1,:card=>'370000000000022222',:birthday=>'2002-02-01',:address=>'青岛',:customer_level => 'vip',:customer_type_id =>3)
    Customer.create(:name => 'Ford',:sex => '男',:customer_no=>'00000003',:phone=>'13800000002',:card_type_id=>1,:card=>'370000000000033333',:birthday=>'2003-03-01',:address=>'青岛',:customer_level => 'vip',:customer_type_id => 4)
    Customer.create(:name => 'Benz',:sex => '女',:customer_no=>'00000004',:phone=>'13800000003',:card_type_id=>1,:card=>'370000000000044444',:birthday=>'2004-04-01',:address=>'青岛',:customer_level => 'vip',:customer_type_id => 5)
    Customer.create(:name => 'Jerry',:login_id =>'Jerry',:password =>'666',:sex => '女',:customer_no=>'00000004',:phone=>'13800000003',:card_type_id=>1,:card=>'370000000000044444',:birthday=>'2004-04-01',:address=>'青岛',:customer_level => 'vip',:customer_type_id => 5)
  end
  
  def self.down
    drop_table :customers
  end
end
